/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * WinnersPrinterPreviewViewImplJDialog.java
 *
 * Created on 19-feb-2010, 18:19:06
 */

package tpdisenio2009.mvp.display;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import tpdisenio2009.model.beans.FantasyTeamPlayer;
import tpdisenio2009.model.beans.FantasyTeamScoreByTournamentDate;
import tpdisenio2009.model.beans.SoccerPlayer;
import tpdisenio2009.model.beans.TournamentDate;
import tpdisenio2009.model.beans.User;

/**
 *
 * @author Pablito
 */
public class WinnersPrinterPreviewViewImpl extends javax.swing.JDialog implements WinnersPrinterPreviewView {

    private TournamentDate currentDate;

    /** Creates new form WinnersPrinterPreviewViewImplJDialog */
    public WinnersPrinterPreviewViewImpl(java.awt.Frame parent, boolean modal, TournamentDate date ) {
        super(parent, modal);
        currentDate = date;       
        initComponents();
        Dimension dim = this.getToolkit().getScreenSize();
        this.setLocation((dim.width - this.getWidth()) / 2,(dim.height - this.getHeight()) / 2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelMisPuntos = new javax.swing.JLabel();
        jLabelNombre = new javax.swing.JLabel();
        jLabelMiPosicion = new javax.swing.JLabel();
        jLabelPuntos = new javax.swing.JLabel();
        jScrollPaneTabla = new javax.swing.JScrollPane();
        jTableTabla = new javax.swing.JTable();
        jLabelPosicion = new javax.swing.JLabel();
        jButtonImprimir = new javax.swing.JButton();
        jLabelFecha = new javax.swing.JLabel();
        jButtonSalir = new javax.swing.JButton();
        jLabelFechaNumero = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tpdisenio2009.Tpdisenio2009App.class).getContext().getResourceMap(WinnersPrinterPreviewViewImpl.class);
        jLabelMisPuntos.setText(resourceMap.getString("jLabelMisPuntos.text")); // NOI18N
        jLabelMisPuntos.setName("jLabelMisPuntos"); // NOI18N

        jLabelNombre.setFont(resourceMap.getFont("jLabelNombre.font")); // NOI18N
        jLabelNombre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelNombre.setText(resourceMap.getString("jLabelNombre.text")); // NOI18N
        jLabelNombre.setName("jLabelNombre"); // NOI18N

        jLabelMiPosicion.setText(resourceMap.getString("jLabelMiPosicion.text")); // NOI18N
        jLabelMiPosicion.setName("jLabelMiPosicion"); // NOI18N

        jLabelPuntos.setFont(resourceMap.getFont("jLabelPuntos.font")); // NOI18N
        jLabelPuntos.setText(resourceMap.getString("jLabelPuntos.text")); // NOI18N
        jLabelPuntos.setName("jLabelPuntos"); // NOI18N

        jScrollPaneTabla.setName("jScrollPaneTabla"); // NOI18N

        jTableTabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Pos", "Apellido y Nombre", "Equipo", "Puntos", "Jugador con mejor puntaje"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableTabla.setName("jTableTabla"); // NOI18N
        jTableTabla.getTableHeader().setReorderingAllowed(false);
        jScrollPaneTabla.setViewportView(jTableTabla);
        jTableTabla.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableTabla.columnModel.title0")); // NOI18N
        jTableTabla.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableTabla.columnModel.title1")); // NOI18N
        jTableTabla.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTableTabla.columnModel.title2")); // NOI18N
        jTableTabla.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTableTabla.columnModel.title3")); // NOI18N
        jTableTabla.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTableTabla.columnModel.title4")); // NOI18N

        jLabelPosicion.setFont(resourceMap.getFont("jLabelPosicion.font")); // NOI18N
        jLabelPosicion.setText(resourceMap.getString("jLabelPosicion.text")); // NOI18N
        jLabelPosicion.setName("jLabelPosicion"); // NOI18N

        jButtonImprimir.setText(resourceMap.getString("jButtonImprimir.text")); // NOI18N
        jButtonImprimir.setToolTipText(resourceMap.getString("jButtonImprimir.toolTipText")); // NOI18N
        jButtonImprimir.setName("jButtonImprimir"); // NOI18N

        jLabelFecha.setText(resourceMap.getString("jLabelFecha.text")); // NOI18N
        jLabelFecha.setName("jLabelFecha"); // NOI18N

        jButtonSalir.setText(resourceMap.getString("jButtonSalir.text")); // NOI18N
        jButtonSalir.setToolTipText(resourceMap.getString("jButtonSalir.toolTipText")); // NOI18N
        jButtonSalir.setName("jButtonSalir"); // NOI18N

        jLabelFechaNumero.setFont(resourceMap.getFont("jLabelFechaNumero.font")); // NOI18N
        jLabelFechaNumero.setText(resourceMap.getString("jLabelFechaNumero.text")); // NOI18N
        jLabelFechaNumero.setName("jLabelFechaNumero"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonSalir))
                            .addComponent(jScrollPaneTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabelFecha)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelFechaNumero)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelMisPuntos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelPuntos)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelMiPosicion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelPosicion)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelFecha)
                    .addComponent(jLabelFechaNumero)
                    .addComponent(jLabelNombre)
                    .addComponent(jLabelMisPuntos)
                    .addComponent(jLabelPuntos)
                    .addComponent(jLabelMiPosicion)
                    .addComponent(jLabelPosicion))
                .addGap(18, 18, 18)
                .addComponent(jScrollPaneTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jButtonImprimir)
                    .addComponent(jButtonSalir))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JLabel jLabelFecha;
    private javax.swing.JLabel jLabelFechaNumero;
    private javax.swing.JLabel jLabelMiPosicion;
    private javax.swing.JLabel jLabelMisPuntos;
    private javax.swing.JLabel jLabelNombre;
    private javax.swing.JLabel jLabelPosicion;
    private javax.swing.JLabel jLabelPuntos;
    private javax.swing.JScrollPane jScrollPaneTabla;
    private javax.swing.JTable jTableTabla;
    // End of variables declaration//GEN-END:variables

    public void setDate( TournamentDate date ) {
        jLabelFechaNumero.setText( date.toString() + "º" );
    }

    public TournamentDate getDate() {
        return currentDate;
    }

    public void setFantasyTeamName(String fantasyTeamName) {
        jLabelNombre.setText( fantasyTeamName );
    }

    public void setOwnPoints(int points) {
        jLabelPuntos.setText( String.valueOf( points ) );
    }

    public void setOwnPosition(int position) {
        jLabelPosicion.setText( String.valueOf( position ) );
    }

    public void loadFantasyTeams( List<FantasyTeamScoreByTournamentDate> fantasyTeamScores, List<FantasyTeamPlayer> bestFantasyTeamPlayers) {
        DefaultTableModel model = (DefaultTableModel) jTableTabla.getModel();
        model.setRowCount( 0 );

        int pos = 1;
        for ( FantasyTeamScoreByTournamentDate fantasyTeam : fantasyTeamScores ) {
            User user = fantasyTeam.getFantasyTeam().getUser();
            String[] values = new String[5];
            values[0] = String.valueOf( pos++ );
            values[1] = user.getLastName() + ", " + user.getFirstName();
            values[2] = fantasyTeam.getFantasyTeam().getName();
            values[3] = String.valueOf( fantasyTeam.getScore() );

            SoccerPlayer best = bestFantasyTeamPlayers.get(pos-2).getSoccerPlayer();
            values[4] = best.getLastName() + ", " + best.getFirstName() + " (" + best.getRealTeam().getName() + ")";

            model.addRow( values );
        }
    }

    public void addPrinterListListener(ActionListener listener) {
        jButtonImprimir.addActionListener( listener );
    }

    public void removePrinterListListener(ActionListener listener) {
        jButtonImprimir.removeActionListener( listener );
    }

    public void addExitListener(ActionListener listener) {
        jButtonSalir.addActionListener( listener );
    }

    public void removeExitListener(ActionListener listener) {
        jButtonSalir.removeActionListener( listener );
    }

    public void close() {
        setDefaultCloseOperation( DISPOSE_ON_CLOSE );
        setVisible( false );
    }

    public void showNotification( String notifiactionMessage, String notificationMessageTitle ) {
        JOptionPane.showMessageDialog( this,
                notifiactionMessage,
                notificationMessageTitle,
                JOptionPane.INFORMATION_MESSAGE);
    }

    public Component asWidget() {
        return this;
    }
}